'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }

  async act() {
    const { ctx } = this;

    console.log(ctx.query);

    const act = ctx.query.act;
    const data = JSON.parse(ctx.query.data);
    if (act === 'd') {
      const jobName = ctx.query.jobname;
      this.app.bus.dispatch(jobName, data);
    } else if (act === 'e') {
      const evtName = ctx.query.evtname;
      this.app.bus.emit(evtName, data);
    }

    ctx.body = '11111';
  }
}

module.exports = HomeController;
